package com.cn.chapter2;

import java.awt.event.ActionListener;
import java.util.HashMap;
import java.util.Map;
import java.util.function.BinaryOperator;

/**
 * Created by chenyuncong on 2018/12/17.
 */
public class Demo01_lambda {
    public static void main(String[] args) {
        Runnable noArguments = () -> System.out.println("Hello World");
        ActionListener oneArgument = event -> System.out.println("button clicked");
        Runnable multiStatement = () ->{
            System.out.print("Hello");
            System.out.println(" World");
        };
        BinaryOperator<Long> add = (x, y) -> x + y;
        BinaryOperator<Long> addExplicit = (Long x, Long y) -> x + y;


        BinaryOperator<Long> addLongs = (x, y) -> {
            return x + y;
        };
        System.out.println(addLongs.apply( 1L , 1L));


        //自定义了一个FunAdd 接口，使用lambda表达式实现时候可以不创建一个类
        FunAdd<Long,Long> fun1 = (x)->{
            return x;
        };
        System.out.println(fun1.apply(2342L));
        //由于都是泛型，可以把接口当作参数
        FunAdd<Integer,HashMap<String,Object>> fun2 = (x)->{
            HashMap<String,Object> map = new HashMap<>();
            map.put("Long",x);
            return map;
        };

        System.out.println(fun2.apply(1111));

    }

}
